export let likelist = {
  namespaced: true,
  state: {
    likelist_data: {},
    like_data: {}
  },
  actions: {
    getLikelist(store, data = {}) {
      let url = "/likelist?uid=" + data.uid + "&timestamp=" + new Date().getTime();
      return new Promise((resolve, reject) => {
        axios.get(url).then(({
          data
        }) => {
          store.commit('setLikelist', data);
          resolve(data);
        }).catch(error => {
          if (error.response) {
            // 请求已发出，但服务器响应的状态码不在 2xx 范围内
            reject(error.response.data)
          }
        });
      });
    },
    getLike(store, data = {}) {
      let url = "/like?id=" + data.id + "&like=" + data.like + "&timestamp=" + new Date().getTime();
      return new Promise((resolve, reject) => {
        axios.get(url).then(({
          data
        }) => {
          store.commit('setLike', data);
          resolve(data);
        }).catch(error => {
          if (error.response) {
            // 请求已发出，但服务器响应的状态码不在 2xx 范围内
            reject(error.response.data)
          }
        });
      });
    },
  },
  mutations: {
    setLikelist(state, data) {
      state.likelist_data = data;
    },
    setLike(state, data) {
      state.like_data = data;
    },
  }
}
